package com.zhao.controller;

import com.zhao.bean.AddressBook;
import com.zhao.bean.R;
import com.zhao.service.AddressBookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/addressBook")
public class AddressBookController {

    //注入Service
    @Autowired
    private AddressBookService addressBookService;

    /**
     * 管理地址 —— 修改保存
     * @param addressBook
     * @return
     */
    @PutMapping
    public R update(@RequestBody AddressBook addressBook){
        //调用service
        int i = addressBookService.BaoCun(addressBook);

        if (i>0){
            return R.success("修改成功");
        }else {
            return R.error("修改失败 ");
        }
    }

    /**
     * 管理地址——删除地址
     * @param ids
     * @return
     */
    @DeleteMapping
    public R delete(Long ids){
        //调用service
        int row = addressBookService.Delete(ids);
        if (row>0){ //删除成功
            return R.success("删除成功");
        }else {
            return R.error("删除失败");
        }
    }
}
